//生产

const {merge} = require('webpack-merge');
const common = require('../webpack.common.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin'); // 引入CleanWebpackPlugin插件

module.exports = merge(common, { // 将webpack.common.js合并到当前文件
    mode:'production',
    module:{
    rules:[
        {
            test: /\.(htm|html)$/i,
            loader: 'html-withimg-loader',
        },
        {
            test: /\.(png|jpg|jpeg|svg|gif)$/,  // 正则匹配图片格式名
            use: [
                {
                    loader: 'file-loader',  // 使用file-loader
                    options: {
                        outputPath: 'imgs',  // 设置打包后图片存放的文件夹名称
                        name:'[name].[hash:5].[ext]',
                        esModule:false,
                        publicPath:"./imgs"
                    }
                },
            ]
        },
    ]
    },
    devtool: 'source-map',  // 会生成对于调试的完整的.map文件，但同时也会减慢打包速度
    plugins: [
        new CleanWebpackPlugin(),  // 所要清理的文件夹名称
        new HtmlWebpackPlugin({
            title: "Webpack App",
            template: "index.html",
            filename: "./index.html"
        }),
    ]
})
